package com.kantboot.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kantboot.redis.http.KantBootRedisSession;
import com.kantboot.user.entity.CesUser;
import com.kantboot.user.entity.CesWechatUser;
import com.kantboot.user.mapper.CesUserMapper;
import com.kantboot.user.mapper.CesWechatUserMapper;
import com.kantboot.user.service.CesUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Service
public class CesUserServiceImpl extends ServiceImpl<CesUserMapper, CesUser> implements CesUserService  {


    @Resource
    private KantBootRedisSession kantBootRedisSession;
    @Resource
    private CesUserMapper cesUserMapper;

    /**
     * 用户id的key名称
     */
    public static final String USER_ID_KEY="user_id";

    /**
     * 获取用户id
     * @param request
     * @return
     */
    public Long getUserId(HttpServletRequest request){
        System.err.println("2222222222");
        Long userId = kantBootRedisSession.getAttribute(USER_ID_KEY, Long.class, request);
        return userId;
    }

    @Override
    public CesUser getUserInfo(HttpServletRequest request) {
        System.err.println("2222222222");
        Long userId=getUserId(request);
        return cesUserMapper.selectById(userId);
    }
}
